﻿package plugin.chatflash.component
{
    import __AS3__.vec.*;
    import cmd.*;
    import com.core.*;
    import com.sh.game.global.*;
    import com.sh.game.util.*;
    import flash.display.*;
    import flash.events.*;
    import flash.geom.*;
    import flash.text.*;

    public class ChannelListPanel extends Sprite
    {
        private var mPanel:BitmapScale9Grid;
        private var mTFList:Vector.<TextField>;
        private var mFrame:DisplayObject;
        private const CHANNEL_TIP:Array;
        private const CHANNEL_LIST:Array;
        private var mTimeOutID:uint = 0;

        public function ChannelListPanel()
        {
            this.CHANNEL_TIP = ["喇叭：“在喇叭频道发言”", "世界：“在世界频道发言”", "行会：“在行会频道发言”", "队伍：“在队伍频道发言”", "私聊：“在私聊频道发言”", "商贸：“在商贸频道发言”", "普通：“在普通频道发言”"];
            this.CHANNEL_LIST = [ChatCMD.ChannelSpecial, ChatCMD.ChannelWorld, ChatCMD.ChannelUnion, ChatCMD.ChannelTeam, ChatCMD.ChannelPrivate, ChatCMD.ChannelShop, ChatCMD.ChannelStage];
            this.mTFList = new Vector.<TextField>;
            this.createChildren();
            return;
        }// end function

        private function createChildren() : void
        {
            var _loc_4:TextField = null;
            this.mPanel = new BitmapScale9Grid(new Bitmap(App.asset.getBitmapData("png.common.s9_tish")), 3, 50, 3, 50);
            this.mPanel.width = 60;
            this.mPanel.height = 140;
            addChild(this.mPanel);
            this.mFrame = new Bitmap(App.asset.getBitmapData("yellowframe"));
            this.mFrame.width = 54;
            this.mFrame.height = 20;
            this.mFrame.x = 3;
            this.mFrame.visible = false;
            addChild(this.mFrame);
            var _loc_1:int = 4;
            var _loc_2:* = this.CHANNEL_LIST.length;
            var _loc_3:int = 0;
            while (_loc_3 < _loc_2)
            {
                
                _loc_4 = new TextField();
                _loc_4.textColor = UIGlobel.chanel2color(this.CHANNEL_LIST[_loc_3]);
                _loc_4.text = UIGlobel.chanelToname(this.CHANNEL_LIST[_loc_3]);
                _loc_4.autoSize = TextFieldAutoSize.CENTER;
                _loc_4.x = 3;
                _loc_4.selectable = false;
                _loc_4.y = _loc_1 + (14 + _loc_1) * _loc_3;
                _loc_4.width = 54;
                _loc_4.addEventListener(MouseEvent.CLICK, this.itemClickHandler, false, 0, true);
                _loc_4.addEventListener(MouseEvent.ROLL_OVER, this.rollOverHandler, false, 0, true);
                _loc_4.addEventListener(MouseEvent.ROLL_OUT, this.rollOutHandler, false, 0, true);
                addChild(_loc_4);
                this.mTFList.push(_loc_4);
                _loc_3++;
            }
            return;
        }// end function

        private function itemClickHandler(event:MouseEvent) : void
        {
            var _loc_3:int = 0;
            var _loc_2:* = this.mTFList.indexOf(TextField(event.currentTarget));
            if (_loc_2 > -1)
            {
                _loc_3 = this.CHANNEL_LIST[_loc_2];
                ModelProxy.change("chat", "selectChannel", _loc_3);
                this.visible = !this.visible;
                this.mFrame.visible = false;
            }
            return;
        }// end function

        private function rollOverHandler(event:MouseEvent) : void
        {
            var _loc_3:Point = null;
            this.mFrame.visible = true;
            this.mFrame.y = event.currentTarget.y;
            var _loc_2:* = this.mTFList.indexOf(TextField(event.currentTarget));
            if (_loc_2 > -1)
            {
                _loc_3 = new Point(GlobalLayer.instance.root.mouseX, GlobalLayer.instance.root.mouseY);
                ModelProxy.change("tips", "normal", {data:this.CHANNEL_TIP[_loc_2], p:_loc_3});
            }
            return;
        }// end function

        private function rollOutHandler(event:MouseEvent) : void
        {
            this.mFrame.visible = false;
            ModelProxy.change("tips", "state", "close");
            return;
        }// end function

        private function stageClickHandler(event:MouseEvent) : void
        {
            this.visible = !this.visible;
            return;
        }// end function

        public function show() : void
        {
            this.visible = !this.visible;
            return;
        }// end function

        public function hide() : void
        {
            this.visible = false;
            return;
        }// end function

    }
}
